package com.lkx.util.strategy;

import com.lkx.util.ExcelTypeEnum;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.InputStream;

/**
 * ClassName: ExcelVersion
 * Function:  ExcelVersion
 *
 * @Date: 2021年09月21日 16:07:17
 * @Author Kaixuan.Li01
 * version V1.0
 */
public class ExcelVersionStrategy implements Strategy {


    @Override
    public Workbook version(String fileType, InputStream is, Workbook wb) throws Exception {
        if (ExcelTypeEnum.EXCEL_THREE.getText().equalsIgnoreCase(fileType)) {
            wb = new HSSFWorkbook(is);
        } else if (ExcelTypeEnum.EXCEL_SEVEN.getText().equalsIgnoreCase(fileType)) {
            wb = new XSSFWorkbook(is);
        } else {
            throw new Exception("您输入的excel格式不正确");
        }
        return wb;
    }
}
